***************************************************************************** * runmlwin help file * * George Leckie and Chris Charlton * Centre for Multilevel Modelling, 2011 ***************************************************************************** ***************************************************************************** * (a) Continuous response models ***************************************************************************** ************************************** * Two-level models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear * Two-level random-intercept model, analogous to xtreg (fitted using IGLS) runmlwin normexam cons standlrt, /// level2(school: cons) /// level1(student: cons) nopause * Two-level random-intercept and random-slope (coefficient) model (fitted * using IGLS)runmlwin normexam cons standlrt, /// level2 (school: cons standlrt) /// level1 (student: cons) nopause * Refit the model suppressing the two pauses in MLwiN (fitted using IGLS) runmlwin normexam cons standlrt, /// level2 (school: cons standlrt) /// level1 (student: cons) nopause * Refit the model, where this time we additionally calculate the level 2 * residuals (fitted using IGLS) runmlwin normexam cons standlrt, /// level2 (school: cons standlrt, residuals(u)) /// level1 (student: cons) nopause * Two-level random-intercept and random-slope (coefficient) model with a * complex level 1 variance function (fitted using IGLS) matrix A = (1,1,0,0,0,1) runmlwin normexam cons standlrt girl, /// level2(school: cons standlrt) /// level1(student: cons standlrt girl, elements(A)) nopause * Two-level random-intercept and random-slope (coefficient) model using * MCMC (where we first fit the model using IGLS to obtain initial values * for the MCMC chains) runmlwin normexam cons standlrt, /// level2 (school: cons standlrt) /// level1 (student: cons) nopause runmlwin normexam cons standlrt, /// level2 (school: cons standlrt) /// level1 (student: cons) /// mcmc(on) initsprevious nopause ************************************** * Multivariate response models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/gcsemv1.dta", clear * Random-intercept bivariate response model (fitted using IGLS) runmlwin /// (written cons female, eq(1)) /// (csework cons female, eq(2)), /// level2(school: (cons, eq(1)) (cons, eq(2))) /// level1(student: (cons, eq(1)) (cons, eq(2))) nopause ************************************** * Cross-classified models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/xc.dta", clear describe tabulate sid, generate(s) local c = 1 forvalues s=2/19 { constraint define `c' [RP3]var(s1) = [RP3]var(s`s') local c = `c' + 1 } * Two-way cross-classified model (fitted using IGLS) runmlwin attain cons, /// level3(cons: s1-s19, diagonal) /// level2(pid: cons) /// level1(pupil: cons) /// constraints(1/18) nopause * Two-way cross-classified model (fitted using MCMC where starting values * for the MCMC chains are manually specified by the user) matrix b = (0,.33,.33,.33) runmlwin attain cons, /// level3(sid: cons) /// level2(pid: cons) /// level1(pupil: cons) /// mcmc(cc) initsb(b) nopause ***************************************************************************** * (b) Discrete response models ***************************************************************************** ************************************** * Binary response multilevel models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/bang.dta", clear generate lc1 = (lc==1) generate lc2 = (lc==2) generate lc3plus = (lc>=3) * Two-level random intercepts logit model (fitted using IGLS MQL1) runmlwin use cons lc1 lc2 lc3plus age, /// level2(district: cons) /// level1(woman) /// discrete(distribution(binomial) link(logit) denominator(cons)) nopause * Two-level random intercepts logit model (fitted using IGLS PQl2 where * IGLS MQL1 estimates from previous model are used as initial values) runmlwin use cons lc1 lc2 lc3plus age, /// level2(district: cons) /// level1(woman) /// discrete(distribution(binomial) link(logit) denominator(cons) pql2) /// initsprevious nopause * Two-level random intercepts probit model (fitted using IGLS PQL2) runmlwin use cons lc1 lc2 lc3plus age, /// level2(district: cons) /// level1(woman) /// discrete(distribution(binomial) link(probit) denominator(cons) pql2) nopause * Two-level random intercepts probit model (fitted using MCMC where IGLS * PQL2 estimates from previous model are used as initial values) runmlwin use cons lc1 lc2 lc3plus age, /// level2(district: cons) /// level1(woman) /// discrete(distribution(binomial) link(probit) denominator(cons)) /// mcmc(on) initsprevious nopause ************************************** * Unordered multinomial response * models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/bang.dta", clear generate lc1 = (lc==1) generate lc2 = (lc==2) generate lc3plus = (lc>=3) * Two-level random intercepts unordered multinomial model (fitted using * IGLS MQL1) runmlwin use4 cons lc1 lc2 lc3plus, /// level2(district: cons) /// level1(woman) /// discrete(distribution(multinomial) link(mlogit) /// denom(cons) basecategory(4)) nopause ************************************** * Ordered multinomial response models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/alevchem.dta", clear egen school = group(lea estab) generate gcseav = gcse_tot/gcse_no egen gcseav_rank = rank(gcseav) generate gcseav_uniform = (gcseav_rank - 0.5)/_N generate gcseavnormal = invnorm(gcseav_uniform) * Two-level random intercepts ordered multinomial model with common * coefficients for predictor variable gcseavnormal (fitted using IGLS PQL2) runmlwin a_point cons (gcseavnormal, contrast(1/5)), /// level2(school: (cons, contrast(1/5))) /// level1(pupil) /// discrete(distribution(multinomial) link(ologit) denom(cons) base(6) pql2) nopause * Two-level random intercepts ordered multinomial model with separate * coefficients for predictor variable gcseavnormal (fitted using IGLS PQL2) runmlwin a_point cons gcseavnormal, /// level2(school: (cons, contrast(1/5))) /// level1(pupil) /// discrete(distribution(multinomial) link(ologit) denom(cons) base(6) pql2) nopause ************************************** * Count data model ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/mmmec.dta", clear generate lnexpected = ln(exp) * Three-level random intercepts Poisson model (fitted using RIGLS MQL1) runmlwin obs cons uvbi, /// level3(nation: cons) /// level2(region: cons) /// level1(county) /// discrete(distribution(poisson) offset(lnexpected)) rigls nopause * Three-level random intercepts Poisson model (fitted using MCMC where IGLS * MQL1 estimates from previous model are used as initial values) runmlwin obs cons uvbi, /// level3(nation: cons) /// level2(region: cons) /// level1(county) /// discrete(distribution(poisson) offset(lnexpected)) /// mcmc(burnin(5000) chain(50000) refresh(500)) initsprevious nopause ***************************************************************************** * (c) Multivariate response models ***************************************************************************** ************************************** * Multivariate discrete and mixed * response models ************************************** * Setup use "http://www.bristol.ac.uk/cmm/media/runmlwin/tutorial.dta", clear generate binexam = (normexam>0) generate binlrt = (standlrt>0) * Two-level bivariate binary response probit model (fitted using IGLS MQL1) runmlwin /// (binexam cons, equation(1)) /// (binlrt cons, equation(2)), /// level1(student:) /// discrete(distribution(binomial binomial) link(probit) denominator(cons cons)) /// nosort nopause ***************************************************************************** exit